import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:uikit/theme/riki_normal_theme.dart';
import 'package:uikit/theme/riki_red_theme.dart';

import '../uikit.dart';
import 'riki_base_theme.dart';

enum RikiThemeType {
  normal, //正常
  red,
}

class RikiTheme {
  static change(BuildContext context, RikiThemeType type) {
    Provider.of<RikiThemeNotifier>(context, listen: false).change(type);
  }

  static RikiThemeType type(BuildContext context) => Provider.of<RikiThemeNotifier>(context, listen: false).type;

  static RikiBaseTheme of(BuildContext context, {bool listen = true}) => Provider.of<RikiThemeNotifier>(context, listen: listen).theme;

  static RikiBaseTheme get current => of(RikiUikit.context, listen: false);
}

class RikiThemeNotifier extends ChangeNotifier {
  static final RikiNormalTheme normalTheme = RikiNormalTheme();

  static final RikiRedTheme redTheme = RikiRedTheme();

  RikiThemeType _type = RikiThemeType.red;

  RikiThemeType get type => _type;

  RikiBaseTheme? _theme;

  RikiBaseTheme get theme => _theme ?? redTheme;

  change(RikiThemeType type) {
    _type = type;
    switch (_type) {
      case RikiThemeType.normal:
        _theme = normalTheme;
        break;
      case RikiThemeType.red:
        _theme = redTheme;
        break;
    }
    notifyListeners();
  }
}
